#include "stdafx.h"
#include "MiniCppUnit.hxx"
#include "leudgrid/toolspath.h"
#include <sstream>

class TestToolsPath : public TestFixture<TestToolsPath>
{
public:
	TEST_FIXTURE( TestToolsPath )
	{
		TEST_CASE( testAssert );
		TEST_CASE( testBinaryPath );
		TEST_CASE( testSetCurrentDir );
	}
	void testAssert()
	{
		ASSERT(3==1+2);
	}
	void testBinaryPath()
	{
		std::stringstream ss;
		ss << LEUD::BinaryPath::path();
		ss << "\\";
		ss << LEUD::BinaryPath::name();
		ASSERT( ss.str() == LEUD::BinaryPath::full() );
	}
	void testSetCurrentDir()
	{
		char oldpath[MAX_PATH];
		GetCurrentDirectory(MAX_PATH,oldpath);
		{
			char path[MAX_PATH];
			GetModuleFileName(NULL,path,MAX_PATH);
			char *p = strrchr(path, '\\');
			*p = '\0';
			std::string bpath = path;
			memset(path,0,MAX_PATH);
			SetCurrentDirectory("c:\\");
			{
				LEUD::BinaryPathAsCurrentPath bac(true);
				GetCurrentDirectory(MAX_PATH,path);
				ASSERT( bpath == path );
			}
			GetCurrentDirectory(MAX_PATH,path);
			ASSERT(std::string("c:\\") == path);
		}
		SetCurrentDirectory(oldpath);
	}
};

REGISTER_FIXTURE( TestToolsPath );

